import 'package:distribution_mall_flutter/assets.dart';
import 'package:distribution_mall_flutter/constant/cf_constant.dart';
import 'package:distribution_mall_flutter/entity/goods/detail/goods_detail_entity.dart';
import 'package:distribution_mall_flutter/generated/l10n.dart';
import 'package:distribution_mall_flutter/provider/goods/product_details.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

class ProductTag extends ConsumerStatefulWidget {
  const ProductTag({super.key});

  @override
  ConsumerState createState() => _ProductTag();
}

class _ProductTag extends ConsumerState<ProductTag> {
  @override
  void initState() {
    super.initState();
  }

  Widget renderTag() {
    return Container(
      padding: const EdgeInsets.only(left: 16, top: 15, bottom: 15),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Padding(
            padding: const EdgeInsets.only(right: 16),
            child: Text(
              S.current.service,
              style: const TextStyle(
                fontSize: 14,
                color: Color(0xFF868D96),
              ),
            ),
          ),
          Image.asset(
            Assets.assets_icons_product_detail_cod_png,
            width: 36,
          ),
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    final List<TagInfo>? taginfos =
        ref.watch(pDetailProvider).detail?.suInfo?.tagInfos;
    bool hasCode = taginfos?.any((TagInfo info) => info.name == 'COD') == true;

    return SliverVisibility(
        visible: hasCode,
        sliver: SliverToBoxAdapter(
          child: Container(
            decoration: const BoxDecoration(
              border: Border(
                  bottom: BorderSide(
                      width: 1, color: ColorConstant.grey233_4),
                  top: BorderSide(width: 1, color: ColorConstant.grey233_4)),
            ),
            child: Row(
              children: [
                renderTag(),
              ],
            ),
          ),
        ));
  }
}
